package com.kitchen.ui.controls.account
{
	import com.kitchen.AbstractIcon;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;

	public class CoinBar extends Sprite
	{
		private var shoper:Object;
		private var numIcon:AbstractIcon;
		private var numItems:Array;
		
		public function CoinBar(main:BitmapData, shoper:Object)
		{
			super();
			this.shoper = shoper;
			this.numItems = new Array();
			this.layout(main);
		}
		
		private function layout(main:BitmapData):void{
			var bg:CoinBgIcon = new CoinBgIcon(main);
			this.addChild(bg);
			this.addNumbers(main, this.shoper.nGold);
			//this.show(123456);
		}
		
		private function addNumbers(main:BitmapData, num:int):void{
			var cy:int = 6;
			var cx:int = 28;
			num += 10000000;
			var numStr:String = num.toString();
			for(var i:int=0; i<numStr.length-1; i++){
				var n:int = int(numStr.substr(i+1, 1));
				var numItem:NumberItem;
				if(i>1){
					numItem = new NumberItem(n, main, NumberItem.N_RED);
				}else{
					numItem = new NumberItem(n, main, NumberItem.N_BLACK);
				}
				numItem.x = cx+i*11;
				numItem.y = cy;
				this.addChild(numItem);
				this.numItems[i] = numItem;
			}
		}
		
		public function show(num:int):void{
			num += 10000000;
			var numStr:String = num.toString();
			for(var i:int=0; i<numStr.length-1; i++){
				var n:int = int(numStr.substr(i+1, 1));
				NumberItem(this.numItems[i]).show(n);
			}
		}
	}
}